package cn.fenglaicaimi.base.util;

import cn.fenglaicaimi.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class UserContext {

    public static final String USER_IN_SESSION = "user";

    public static HttpServletRequest getRequest(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()  ;
        return request;
    }


    public static void setCurrent(User user) {
        getRequest().getSession().setAttribute(USER_IN_SESSION,user);
    }

    public static User getCurrent(){
        return (User) getRequest().getSession().getAttribute(USER_IN_SESSION);

    }
}
